package com.hsd.mapper.impl;

import com.hsd.mapper.ICategoryDao;
import com.hsd.entity.Category;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.query.Query;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;
@Repository
public class ICategoryDaoImpl implements ICategoryDao {
    @Resource
    private SessionFactory sessionFactory;

    /**
     * 获取当前线程的session
     * @return
     */
    private Session getSession(){
        return sessionFactory.openSession();
    }
    @Override
    public List<Category> selectAll() {
        String hql="from Category category";
        Query query = getSession().createQuery(hql);
        List<Category> list = query.list();
        return list;
    }
}
